package com.gasstation

import com.gasstation.domain.GasUtil

class InventoryPremiumController {

	static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

	def index = {
		redirect(action: "list", params: params)
	}

	def list = {
		params.max = Math.min(params.max ? params.int('max') : 10, 100)
		[inventoryPremiumInstanceList: InventoryPremium.list(params), inventoryPremiumInstanceTotal: InventoryPremium.count()]
	}

	def listAsPerMonth = {
		params.max = Math.min(params.max ? params.int('max') : 10, 100)
		def c = InventoryPremium.createCriteria()
		Date month = params.monthYear
		if(month == null){
			month = new Date()
		}
		def premiumInvList = c.list{between("transactionOn", GasUtil.getFirstDayOfMonth(month), GasUtil.getLastDayOfMonth(month))}
		render(view: "list", model: [inventoryPremiumInstanceList:premiumInvList, monthYear:month, inventoryPremiumInstanceTotal: InventoryPremium.count()])
	}
}
